Building Apple Watch Projects by Stuart Grimshaw

Building Apple Watch Projects by Stuart Grimshaw

Author:Stuart Grimshaw
Language: eng
Format: mobi
Publisher: Packt Publishing
Published: 2016-02-28T22:00:00+00:00


Interface Controllers

Now the SessionManager class is ready to test. To do this, we simply need to create the sharedInstance in the InterfaceController class which we will now implement.

In the project navigator, select InterfaceController.swift, and add the following code to the InterfaceController class's awakeWithContext method:

override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) requestWeatherData() }

The compiler will complain about not knowing any such method, so we'll fix that now.

Add the following function to the InterfaceController class:

func requestWeatherData() { //1 WeatherSessionManager.sharedInstance.fetchWeatherData() { //2 (data: NSData?, response: NSURLResponse?, taskError: NSError?) -> Void in if taskError == nil { //3 do { let jsonData = try NSJSONSerialization.JSONObjectWithData( data!, options: .AllowFragments) as! jsonDict print(jsonData) //4 } catch let jsonErrorasNSError { print(jsonError.localizedDescription) } } } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.